<script setup>
const props = defineProps({
  detail: Object,
  commands: Array,
  status: Array,
  statusColors: Array
})
const dialogVisible = defineModel()

function tableRowClassName(row) {
  if (row.command === props.detail?.currentCommand) {
    return 'bg-primary'
  }
  return ''
}
</script>

<template>
  <el-dialog v-model="dialogVisible" width="768px" v-bind="$attrs">
    <div class="text-base">
      <div class="p-4">
        <div>
          <div class="text-lg">AAA摄像头</div>
        </div>
        <div class="mt-4 grid grid-cols-2 gap-4">
          <div class="flex">
            <div class="w-28">设备状态 :</div>
            <span
              v-if="props.status[props.detail?.deviceStatus]"
              :class="props.statusColors[props.detail?.deviceStatus]"
            >
              {{ props.status[props.detail?.deviceStatus] }}
            </span>
          </div>
          <div v-if="props.detail?.deviceRunTime" class="flex">
            <div class="w-28">运行时长 :</div>
            {{ props.detail?.deviceRunTime }}
          </div>
          <div class="flex">
            <div class="w-28">当前IP :</div>
            {{ props.detail?.deviceIp }}
          </div>
          <div class="flex">
            <div class="w-28">当前应用版本 :</div>
            {{ props.detail?.deviceAppName }}
          </div>
          <div class="flex">
            <div class="w-28">当前AI版本 :</div>
            {{ props.detail?.deviceAiName }}
          </div>
        </div>
      </div>
      <div class="mt-4 p-2">指令记录</div>
      <el-table
        :data="commands ?? []"
        style="width: 100%"
        :cell-style="{
          textAlign: 'center'
        }"
        :header-cell-style="{
          textAlign: 'center'
        }"
        align="center"
        :row-class-name="tableRowClassName"
      >
        <el-table-column type="index" label="序号" width="55" fixed="left" />
        <el-table-column prop="command" label="指令内容" />
        <el-table-column prop="sendTime" label="发送时间" />
      </el-table>
    </div>
    <template #footer>
      <el-button @click="dialogVisible = false"> 关闭 </el-button>
    </template>
  </el-dialog>
</template>
